package com.budwk.app.sqfwV2.enums;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

@Getter
@AllArgsConstructor
public enum SafetyCheckV2NewEnums {

    A(1, "九小场所", "sqfwV2/centuryCitySecurityNew/jxcs_ty.docx", "sqfwV2/centuryCitySecurityNew/jxcs_cy_mr_yl.docx","sqfwV2/centuryCitySecurity/templet/九小场所安全隐患排查登记.docx", "“九小场所”安全隐患排查登记合集", "全部数据|九小场所","/preview/safety/sjc/九小图_pdf.png"),
    B(2, "多业态混合经营场所", "sqfwV2/centuryCitySecurityNew/dyth.docx", null,"sqfwV2/centuryCitySecurityNew/templet/多业态混合经营场所安全隐患排查登记表.docx", "“多业态混合经营场所”安全隐患排查登记表合集", "全部数据|多业态混合经营场所","/preview/safety/sjc/多业态图_pdf.png"),
    C(3, "人员密集场所", "sqfwV2/centuryCitySecurityNew/rymj.docx", null,"sqfwV2/centuryCitySecurityNew/templet/人员密集场所安全隐患排查登记表.docx", "“人员密集场所”安全隐患排查登记表合集", "全部数据|人员密集场所","/preview/safety/sjc/人员密集图_pdf.png"),
    D(5, "重点场所", "sqfwV2/centuryCitySecurityNew/zdcs.docx", null,"sqfwV2/centuryCitySecurityNew/templet/重点场所安全隐患排查登记表.docx", "“重点场所”安全隐患排查登记表合集", "全部数据|重点场所","/preview/safety/sjc/重点场所图_pdf.png"),
    E(4, "楼宇", "sqfwV2/centuryCitySecurityNew/ly.docx", null,"sqfwV2/centuryCitySecurityNew/templet/楼宇安全隐患排查登记表.docx", "“楼宇”安全隐患排查登记表合集", "全部数据|楼宇场所","/preview/safety/sjc/楼宇图_pdf.png"),
    F(6, "住宅楼栋", "sqfwV2/centuryCitySecurityNew/zzld.docx",null, "sqfwV2/centuryCitySecurityNew/templet/住宅楼栋安全隐患排查登记表.docx", "“住宅楼栋”安全隐患排查登记表合集", "全部数据|住宅楼栋","/preview/safety/sjc/住宅图_pdf.png"),
    H(7, "建筑工地", "sqfwV2/centuryCitySecurityNew/jzgdV3.docx",null, "sqfwV2/centuryCitySecurityNew/templet/建筑工地安全隐患排查登记表.docx", "“建筑工地”安全隐患排查登记表合集", "全部数据|建筑工地","/preview/safety/sjc/建筑工地图_pdf.png"),
    G(8, "九小场所", "sqfwV2/centuryCitySecurityNew/cateringServiceCheck.docx", null,"sqfwV2/centuryCitySecurityNew/templet/餐饮服务日常巡查表.docx", "餐饮服务日常巡查表合集", "全部数据|餐饮","/preview/safety/sjc/餐饮服务_pdf.png"),
    K(9, "九小场所", "sqfwV2/centuryCitySecurityNew/foodSalesCheck.docx",null, "sqfwV2/centuryCitySecurityNew/templet/食品销售日常巡查表.docx", "食品销售日常巡查表合集", "全部数据|餐饮","/preview/safety/sjc/食品销售_pdf.png"),
    L(10, "人员密集场所", "sqfwV2/centuryCitySecurityNew/canteen.docx",null, "sqfwV2/centuryCitySecurityNew/templet/学校食堂食品安全专项监督检查表.docx", "学校食堂食品安全专项监督检查表合集", "全部数据|食堂","/preview/safety/sjc/学校食堂_pdf.png"),

    ;


    private int code;
    private String name;//归属的场所类型
    private String templat;
    private String templatCyMrYl;
    private String templatUrl;
    private String mergePdf;
    private String label;
    private final String previewImage;

    public static String getTemplatName(String name) {
        List<SafetyCheckV2NewEnums> list = Arrays.asList(SafetyCheckV2NewEnums.values())
                .stream()
                .filter(e -> name.equals(e.getName()))
                .collect(Collectors.toList());
        if (list.size() > 0) {
            return list.get(0).getTemplat();
        }
        return null;
    }

    public static String getName(Integer code) {
        String name = Arrays.asList(SafetyCheckV2NewEnums.values())
                .stream()
                .filter(e -> code.equals(e.getCode()))
                .collect(Collectors.toList())
                .get(0)
                .getName();
        return name;
    }

    public static String getmergePdf(Integer code) {
        String mergePdf = Arrays.asList(SafetyCheckV2NewEnums.values())
                .stream()
                .filter(e -> code.equals(e.getCode()))
                .collect(Collectors.toList())
                .get(0)
                .getMergePdf();
        return StrUtil.format("{}_{}", mergePdf, DateUtil.format(new Date(), "yyyyMMddHHmmss"));
    }

    public static String getSourceMergePdf(Integer code) {
        String mergePdf = Arrays.asList(SafetyCheckV2NewEnums.values())
                .stream()
                .filter(e -> code.equals(e.getCode()))
                .collect(Collectors.toList())
                .get(0)
                .getMergePdf();
        return mergePdf;
    }

    public static String getTemplatePath(Integer code) {
        String templatePath = Arrays.asList(SafetyCheckV2NewEnums.values())
                .stream()
                .filter(e -> code == e.getCode())
                .collect(Collectors.toList())
                .get(0)
                .getTemplat();
        return templatePath;
    }


    public static String getUrl(Integer code) {
        String url = Arrays.asList(SafetyCheckV2NewEnums.values())
                .stream()
                .filter(e -> code.equals(e.getCode()))
                .collect(Collectors.toList())
                .get(0)
                .getTemplatUrl();
        return  url;
    }

    public static SafetyCheckV2NewEnums getTemplatEnums(String templatePath) {
        SafetyCheckV2NewEnums meetingEnums = Arrays.asList(SafetyCheckV2NewEnums.values())
                .stream()
                .filter(e -> e.getTemplat().equals(templatePath))
                .collect(Collectors.toList())
                .get(0);
        return meetingEnums;
    }

    /**
     * @param code
     * @return
     */
    public static String getLabel(String code) {
        Optional<SafetyCheckV2NewEnums> optional = Arrays.stream(values()).filter(e -> e.getCode() == Integer.parseInt(code)).findFirst();
        return optional.map(SafetyCheckV2NewEnums::getLabel).orElse(null);
    }

    public static Integer getCodeByName(String name) {
        Integer code = Arrays.asList(SafetyCheckV2NewEnums.values())
                .stream()
                .filter(e -> name.equals(e.getName()))
                .collect(Collectors.toList())
                .get(0)
                .getCode();
        return code;

    }

    public static List<SafetyCheckV2NewEnums> getTemplate(String name) {
        List<SafetyCheckV2NewEnums> templat = Arrays.asList(SafetyCheckV2NewEnums.values())
                .stream()
                .filter(e -> name.equals(e.getName()))
                .collect(Collectors.toList());
        return templat;
    }

    public static SafetyCheckV2NewEnums getSafetyCheckV2EnumsByCode(Integer code) {
        for (SafetyCheckV2NewEnums o : SafetyCheckV2NewEnums.values()) {
            if (o.code == code) {
                return o;
            }
        }
        return null;
    }

}
